package cn.john.user.controller;

import cn.john.basic.exception.BusinessException;
import cn.john.basic.util.AjaxResult;
import cn.john.user.service.IVerifyCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {
    @Autowired
    private IVerifyCodeService verifyCodeService;

    /**
     * 前端传对象，一定程度可以用map代替对象接收参数
     * @param param 需要发送的手机和业务类型
     * @return
     */
    @PostMapping("/sendSmsCode")
    public AjaxResult sendSmsCode(@RequestBody Map<String,String> param) {
        try {
            verifyCodeService.sendSmsCode(param);
            return new AjaxResult();
        }catch (BusinessException e){
            return new AjaxResult().setMessage("发送验证码失败! 原因:" + e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult().setMessage("系统繁忙，请稍后再试！");
        }
    }

}
